#include "Scene.h"
#include <GL/gl.h>
#include "opengl.h"
#include <math.h>

const int NBROT=50;



void draw_axes()
{
    glLineWidth(5);
    glBegin( GL_LINES );

    glColor3f( 1.f, 0.f, 0.f);
    glVertex3f( 0.f, 0.f, 0.f);
    glVertex3f( 1.f, 0.f, 0.f);

    glColor3f( 0.f, 1.f, 0.f);
    glVertex3f( 0.f, 0.f, 0.f);
    glVertex3f( 0.f, 1.f, 0.f);

    glColor3f( 0.f, 0.f, 1.f);
    glVertex3f( 0.f, 0.f, 0.f);
    glVertex3f( 0.f, 0.f, 1.f);

    glEnd();
}


void draw_grid()
{
    int i;
    glLineWidth(1);
    glColor3f( 1.f, 1.f, 1.f);

    glPushMatrix();
    glTranslatef( -5, 0, -5);

    glBegin( GL_LINES );

    for (i=0;i<=10;++i)
    {
        glVertex3f( i, 0, 0);
        glVertex3f( i, 0, 10);
    }

    for (i=0;i<=10;++i)
    {
        glVertex3f( 0, 0, i);
        glVertex3f( 10, 0, i);
    }

    glEnd();
    glPopMatrix();
}



void draw_cube()
{
    static float pt[8][3] = { {0,0,0}, {1,0,0}, {1,0,1}, {0,0,1}, {0,1,0}, {1,1,0}, {1,1,1}, {0,1,1} };
    static int f[6][4] = { {0,1,2,3}, {5,4,7,6}, {1,5,6,2}, {0,3,7,4}, {3,2,6,7}, {0,4,5,1} };
    static float n[6][3] = { {0,-1,0}, {0,1,0}, {1,0,0}, {-1,0,0}, {0,0,1}, {0,0,-1} };
    static float uv[4][2] = { {0,0}, {1,0}, {1,1}, {0,1} };
    int i,j;

    glTranslatef(-0.5,-0.5,-0.5);
    glBegin(GL_QUADS);
    for (i=0;i<6;i++)
    {
        glNormal3f( n[ i ][0], n[ i ][1], n[ i ][2] );
        for (j=0;j<4;j++)
        {
            glTexCoord2f( uv[j][0], uv[j][1] );
            glVertex3f( pt[ f[i][j] ][0], pt[ f[i][j] ][1], pt[ f[i][j] ][2] );
        }
    }
    glEnd();
}



void draw_sphere()
{
    const int N=64, M=N/2;
    float a,a_suiv,b;
    int i,j;
    for(i=0;i<M;i++){
        a=i*M_PI/M;
        a_suiv=(i+1)*M_PI/M;
        glBegin(GL_TRIANGLE_STRIP);

        for(j=0;j<=N;j++){
            b=j*2*M_PI/N;
            glNormal3f(sin(a)*cos(b),cos(a),sin(a)*sin(b));
			glTexCoord2f(b/(2*M_PI),0.5+(a/M_PI));

			glVertex3f(sin(a)*cos(b),cos(a),sin(a)*sin(b));
			glTexCoord2f(b/(2*M_PI),0.5+(a_suiv/M_PI));

			glVertex3f(sin(a_suiv)*cos(b),cos(a_suiv),sin(a_suiv)*sin(b));
        }
        glEnd();
    }
}



void draw_cylinder()
{
    const int N=36;
    int i;
    float alpha;

/** cylindre */
    glBegin(GL_TRIANGLE_STRIP);
    for(i=0;i<=N;i++){
        alpha=i*(2*M_PI/N);
        glNormal3f(cos(alpha),0.5,sin(alpha));
        glVertex3f(cos(alpha),0,sin(alpha));
        glVertex3f(cos(alpha),0.5,sin(alpha));
    }
    glEnd();
/** Cercle superieur */
    glBegin(GL_TRIANGLE_FAN);

    glVertex3f(0,0.5,0);
    for(i=0;i<=N;i++){
        alpha=i*2*M_PI/N;
        glVertex3f(cos(alpha),0.5,sin(alpha));
    }
    glEnd();
/** Cercle inferieur */
    glBegin(GL_TRIANGLE_FAN);
    glVertex3f(0,0,0);
    for(i=0;i<=N;i++){
        alpha=i*(2*M_PI/N);
        glNormal3f(cos(alpha),0,sin(alpha));

        glVertex3f(cos(alpha),0,sin(alpha));

    }
    glEnd();

}



void draw_cone()
{
    int i;float alpha;
    const   int N=36;
    /** Cone */
    glBegin(GL_TRIANGLE_FAN);
    //glColor3f( 1, 1, 0);
    glVertex3f(0,1,0);
    for(i=0;i<=N;i++){
        alpha=i*2*M_PI/N;
        glNormal3f(cos(alpha),1,sin(alpha));
        glVertex3f(cos(alpha),0,sin(alpha));
    }
    glEnd();
/** Cercle inferieur */
    glBegin(GL_TRIANGLE_FAN);
    glVertex3f(0,0,0);
    for(i=0;i<=N;i++){
        alpha=i*(2*M_PI/N);
        glVertex3f(cos(alpha),0,sin(alpha));
    }
    glEnd();
}


/****************** Initialisation Scene ******************/
void sceneInit(Scene& sc)
{
    animInit( sc.anim, "data/anim1.ani" );
    imInitPPM(sc.terrain,"data/terrain/terrain.ppm");
    sc.tex_tree = LoadGLTexture("data/billboard/arbre.ppm", true);
    sc.tex_terrain = LoadGLTexture("data/terrain/terrain_texture_bruit.ppm",true);
    sc.cubemap1 = LoadGLTexture("data/cubemap/cubemap_opensea/opensea_posz.ppm", true);
    sc.cubemap2 = LoadGLTexture("data/cubemap/cubemap_opensea/opensea_negz.ppm", true);
    sc.cubemap3 = LoadGLTexture("data/cubemap/cubemap_opensea/opensea_posx.ppm", true);
    sc.cubemap4 = LoadGLTexture("data/cubemap/cubemap_opensea/opensea_negx.ppm", true);
    sc.cubemap5 = LoadGLTexture("data/cubemap/cubemap_opensea/opensea_posy.ppm", true);
    sc.cubemap6 = LoadGLTexture("data/cubemap/cubemap_opensea/opensea_negy.ppm", true);
    sc.tex_monde = LoadGLTexture("data/monde.ppm", true);
    sc.tex_soleil = LoadGLTexture("data/soleil.ppm", true);
    sc.tex_lune = LoadGLTexture("data/lune.ppm", true);
/** animation camion */
    animInit( sc.anim_camion, "data/anim1.ani" );

/****** calcule des positions des arbres sur le terrain *****/
	int dimx=imGetDimX(sc.terrain);
	for(int i=0; i < 20 ; i++){
		sc.pos[i][0]=random()%dimx;
		sc.pos[i][1]=getPixConst(sc.terrain,sc.pos[i][0],sc.pos[i][0]);
		sc.pos[i][2]=random()%dimx;

	}
}
/************************************************************************************************/

void dessineTerrain(const    Image    &im){
	int i,j;
    for(i=1;i<im.dimx-2;i++){
        glBegin(GL_TRIANGLE_STRIP);

        for(j=1;j<im.dimy-1;j++){
            normalTerrain(im,i,j);
            glTexCoord2f(((float)i)/im.dimx,((float)j)/im.dimx);
            glVertex3f(i,getPix(im,i,j),j);

            normalTerrain(im,i+1,j);
            glTexCoord2f(((float)i+1)/im.dimx,((float)j)/im.dimy);
            glVertex3f(i+1,getPix(im,i+1,j),j);
        }
        glEnd();
    }

}

void normalTerrain(const Image&  im,int i,int   j){
    Vec3f A,B,C,D,AB,CD,N;

    vecInit(A,i-1,getPix(im,i-1,j),j);
    vecInit(B,i+1,getPix(im,i+1,j),j);
    vecInit(C,i,getPix(im,i,j+1),j+1);
    vecInit(D,i,getPix(im,i,j-1),j-1);

    vecSub(AB,B,A);
    vecSub(CD,D,C);
    vecCross(N,AB,CD);
    glNormal3f(N.x,N.y,N.z);

}


/************************************************************************************************/



/** à utiliser dans le cas où on veut desiner notre propre arbre avec des formes en Y */
float fRand(){
    return(rand()%1000);
}
/** à utiliser dans le cas où on veut desiner notre propre arbre avec des formes en Y */
void dArbre(int niveau, float l){
	/*
	if (niveau == 0) return ;

    //float L;
    //L= l+ fRand()*l*0.1;
    float a1,a2;
    a1=45+0.1*45;
    a2=45+0.1*45;

    glPushMatrix();
        cylindre(0.1*l, l , 0.1*l);
        glTranslatef(0,l,0);

        glPushMatrix();
            glRotatef(a1,0,0,1);
            glRotatef(120,0,1,0);
            dArbre(niveau-1,0.75*l);
        glPopMatrix();

        glPushMatrix();
            glRotatef(-a2,0,0,1);
            glRotatef(240,0,1,0);
            dArbre(niveau-1,0.75*l);
        glPopMatrix();
    glPopMatrix();
	*/

}
/** à utiliser dans le cas où on veut desiner notre propre arbre avec des formes en Y */
void dBranche(float sx, float sy, float sz){
    /*
	int i;
    float x,y,z;
    glColor3f(0.1,0.6,0.1);
    //cylindre(sx,sy,sz);
    glColor3f(0,1,0);
    glBegin(GL_TRIANGLE_STRIP);
    for(i=0;i<20;i++){
        x=fRand()*sx*2 - sx;
        y=fRand()*sy*2 - sy;
        z=fRand()*sz*2 - sz;
        glVertex3f(x,y,z);
    }
    glEnd();
	*/
}

void dessine_arbre()
{
	glBegin(GL_QUADS);

		glTexCoord2f(1,1);
		glVertex3f(0,0,0);

		glTexCoord2f(1,0);
		glVertex3f(0,1,0);

		glTexCoord2f(0,0);
		glVertex3f(1,1,0);

		glTexCoord2f(0,1);
		glVertex3f(1,0,0);

	glEnd();


	glBegin(GL_QUADS);
		glTexCoord2f(1,1);
		glVertex3f(0.5,0,0.5);

		glTexCoord2f(1,0);
		glVertex3f(0.5,1,0.5);

		glTexCoord2f(0,0);
		glVertex3f(0.5,1,-0.5);

		glTexCoord2f(0,1);
		glVertex3f(0.5,0,-0.5);

	glEnd();
}

void dessine_foret(const Scene& sc){
	int a;

    //for(i=1;i<im.dimx-2;i++){
        //for(j=1;j<im.dimy-1;j++){
            for(a=0;a<40;a++){
                glPushMatrix();
                    glEnable(GL_BLEND);
                   glEnable(GL_ALPHA_TEST);
                   glEnable(GL_TEXTURE_2D);
                   glBindTexture(GL_TEXTURE_2D, sc.tex_tree);
                   // glTranslatef(i,getPix(im,i,j),j);
                   glTranslatef(sc.pos[a][0]%30,sc.pos[a][1]%3,sc.pos[a][2]%30);

                    dessine_arbre();
                    glDisable(GL_LIGHTING);
                   glDisable(GL_BLEND);
                   glDisable(GL_ALPHA_TEST);
                   glDisable(GL_TEXTURE_2D);
                glPopMatrix();
            }
        //}
	//}
}

void cubmap(const Scene& sc){

    glEnable(GL_NORMALIZE);
    glDisable(GL_LIGHTING);
    glDisable(GL_BLEND);
    glDisable(GL_ALPHA_TEST);

	/** Dessiner face 1 avec chargement de texture**/
    glNormal3f(0,0,1);
    glBindTexture(GL_TEXTURE_2D, sc.cubemap1);

	glBegin(GL_QUADS);
    glTexCoord2f( 1,1 );glVertex3f(1,0,0);
    glTexCoord2f( 0,1 );glVertex3f(1,0,-1);
    glTexCoord2f( 0,0 );glVertex3f(1,1,-1);
    glTexCoord2f( 1,0 );glVertex3f(1,1,0);
    glEnd();

	/** Dessiner face 2 avec chargement de texture**/
    glNormal3f(-1,0,0);
    glBindTexture(GL_TEXTURE_2D, sc.cubemap2);

    glBegin(GL_QUADS);
    glTexCoord2f( 1,1 );glVertex3f(0,0,-1);
    glTexCoord2f( 0,1 );glVertex3f(0,0,0);
    glTexCoord2f( 0,0 );glVertex3f(0,1,0);
    glTexCoord2f( 1,0 );glVertex3f(0,1,-1);
    glEnd();

	/** Dessiner face 3 avec chargement de texture**/
	glNormal3f(1,0,0);
    glBindTexture(GL_TEXTURE_2D, sc.cubemap3);

    glBegin(GL_QUADS);
    glTexCoord2f( 1,1 );glVertex3f(0,0,0);
    glTexCoord2f( 0,1 );glVertex3f(1,0,0);
    glTexCoord2f( 0,0 );glVertex3f(1,1,0);
    glTexCoord2f( 1,0 );glVertex3f(0,1,0);
    glEnd();

	/** Dessiner face 4 avec chargement de texture**/
    glNormal3f(0,0,-1);
    glBindTexture(GL_TEXTURE_2D, sc.cubemap4);

    glBegin(GL_QUADS);
    glTexCoord2f( 1,1);glVertex3f(1,0,-1);
    glTexCoord2f( 0,1 );glVertex3f(0,0,-1);
    glTexCoord2f( 0,0 );glVertex3f(0,1,-1);
    glTexCoord2f( 1,0 );glVertex3f(1,1,-1);
    glEnd();

	/** Dessiner face 5 avec chargement de texture**/
    glNormal3f(0,1,0);
    glBindTexture(GL_TEXTURE_2D, sc.cubemap5);

    glBegin(GL_QUADS);
    glTexCoord2f( 1,0 );glVertex3f(0,1,0);
    glTexCoord2f( 1,1 );glVertex3f(1,1,0);
    glTexCoord2f( 0,1 );glVertex3f(1,1,-1);
    glTexCoord2f( 0,0 );glVertex3f(0,1,-1);
    glEnd();

	/** Dessiner face 6 avec chargement de texture**/
    glNormal3f(0,-1,0);
    glBindTexture(GL_TEXTURE_2D, sc.cubemap6);

    glBegin(GL_QUADS);
    glTexCoord2f( 1,1 );glVertex3f(0,0,0);
    glTexCoord2f( 0,1 );glVertex3f(1,0,0);
    glTexCoord2f( 0,0 );glVertex3f(1,0,-1);
    glTexCoord2f( 1,0 );glVertex3f(0,0,-1);
    glEnd();

    glDisable(GL_TEXTURE_2D);
    glEnable(GL_LIGHTING);
    glEnable(GL_BLEND);
    glEnable(GL_ALPHA_TEST);

/* Version Vu en TD !!
	glNormal3f(0,0,1);
    glBindTexture(GL_TEXTURE_2D, sc.cubemap1);
    glBegin(GL_QUADS);
	//  1
    glTexCoord2f(0.75f,2.0f/3); //G
    glVertex3f(1,1,0);

    glTexCoord2f(0.5f,2.0f/3); // H
    glVertex3f(0,1,0);

    glTexCoord2f(0.5f,1.0f/3); // E
    glVertex3f(0,0,0);

    glTexCoord2f(0.75f,1.0f/3); // F
    glVertex3f(1,0,0);

    //  2
    glTexCoord2f(0.5f,2.0f/3); //H
    glVertex3f(0,1,0);

    glTexCoord2f(0.25f,2.0f/3); // D
    glVertex3f(0,1,1);

    glTexCoord2f(0.25f,1.0f/3); // A
    glVertex3f(0,0,1);

    glTexCoord2f(0.5f,2.0f/3); // E
    glVertex3f(0,0,0);

   //  3
    glTexCoord2f(0.25f,2.0f/3); // D
    glVertex3f(0,1,1);

    glTexCoord2f(0.0f,2.0f/3); // C
    glVertex3f(1,1,1);

    glTexCoord2f(0.0f,1.0f/3); // B
    glVertex3f(1,0,1);

    glTexCoord2f(0.25f,1.0f/3); // A
    glVertex3f(0,0,1);

    //  4
    glTexCoord2f(1.0f,2.0f/3); // C
    glVertex3f(1,1,1);

    glTexCoord2f(0.75f,2.0f/3); //G
    glVertex3f(1,1,0);

    glTexCoord2f(0.75f,1.0f/3); // F
    glVertex3f(1,0,0);

    glTexCoord2f(1.0f,1.0f/3); // B
    glVertex3f(1,0,1);

    //  5
    glTexCoord2f(0.75f,1.0f); // C
    glVertex3f(1,1,1);

    glTexCoord2f(0.5f,1.0f); // D
    glVertex3f(0,1,1);

    glTexCoord2f(0.5f,2.0f/3); //H
    glVertex3f(0,1,0);

    glTexCoord2f(0.75f,2.0f/3); //G
    glVertex3f(1,1,0);

   //  6
    glTexCoord2f(0.75f,1.0f/3); // F
    glVertex3f(1,0,0);

    glTexCoord2f(0.5f,1.0f/3); // E
    glVertex3f(0,0,0);

    glTexCoord2f(0.5f,0.0f); // A
    glVertex3f(0,0,1);

    glTexCoord2f(0.75f,0.0f); // B
    glVertex3f(1,0,1);
*/

}



void dessine_camion(const Scene& sc){
/************ Dessiner Cube 1 ************/

    glPushMatrix();	// sauvegarde la transformation courante
		glTranslatef( -2, 1.5,0);
		glScalef(4,2,2);
		glColor3f( 1, 0, 0);
		draw_cube();
		glDisable(GL_TEXTURE_2D);
    glPopMatrix();

	float x0=-5,     y0=1,   z0= 0;
    float x1=-3,     y1=1,   z1=-2;
    float x2=-3,     y2=1,   z2= 2;
    float x3=-7,     y3=1,   z3=-2;
    float x4=-7,     y4=1,   z4= 2;
    float x5=-4,     y5=1.5, z5= 0;
    float x6=-4.5,   y6=1,   z6= 0;

    glPushMatrix();

    glTranslatef( x0, y0, z0);
    glColor3f( 1, 0, 0);
    glRotatef(90,0,0,1);
    glScalef(0.5,0.5,0.5);

    draw_cone();
    glPopMatrix();

/************ Dessiner les roues  du Camion ************/
/************ cylindre    1 ************/
    glPushMatrix();
		glColor3f( 0.2,0.2,0.2);
    //code  pr  rotation    et  reduction   volume
		glScalef(0.5,0.5,0.5);
		glTranslatef( x1, y1, z1);
		glRotatef(-90,1,0,0);
			draw_cylinder();
    glPopMatrix();
/************ cylindre    2 ************/
    glPushMatrix();
		glScalef(0.5,0.5,0.5);
		glTranslatef( x2, y2, z2);
		glRotatef(90,1,0,0);
		glColor3f( 0.2,0.2,0.2);

		draw_cylinder();
    glPopMatrix();
/************ cylindre    3 ************/

    glPushMatrix();
		glScalef(0.5,0.5,0.5);
		glTranslatef( x3, y3, z3);
		glRotatef(-90,1,0,0);
		glColor3f( 0.2,0.2,0.2);
		draw_cylinder();
    glPopMatrix();
/************ cylindre    4 ************/

    glPushMatrix();
		glScalef(0.5,0.5,0.5);
		glTranslatef( x4, y4, z4);
		glRotatef(90,1,0,0);
		glColor3f( 0.2,0.2,0.2);
		draw_cylinder();
    glPopMatrix();
/************    Sphere    ************/
    glPushMatrix();
		glTranslatef( x5, y5, z5);
		glColor3f( 1, 1, 0);
		draw_sphere();
    glPopMatrix();
/*********  Dessiner Cube 2   ************/
    glPushMatrix();
		glTranslatef( x6, y6, z6);
		glScalef(1,1,2);
		glColor3f( 1, 0, 1);
		draw_cube();
    glPopMatrix();
}

void anim_camion(const Scene& sc){
	glPushMatrix();
		float t=temps();
		int temps_entier=int(t);
		int temps_entier_ok = temps_entier % sc.anim.nbp;

		int suiv=(temps_entier+1)%sc.anim.nbp;
		float poids = t-temps_entier;
		Vec3f pos1,pos2,posf;
		vecSub(pos1,sc.anim.P[suiv],sc.anim.P[temps_entier_ok]);
		vecMul(pos2, poids, pos1);
		vecAdd(posf,pos2,sc.anim.P[temps_entier_ok]);
		//glTranslatef(posf.x,posf.y,posf.z);
		//glTranslatef(-posf.x,0,0);
		//glRotatef(180,1,0,0);

		//glScalef(0.4,0.4,0.4);
		glEnable(GL_TEXTURE_2D);

		trajet_camion(sc);

		glDisable(GL_TEXTURE_2D);

	glPopMatrix();
}
void trajet_camion(const Scene& sc){
	glPushMatrix();
		float t=temps();
		int temps_entier=int(t);
		float angleRot= 180/NBROT;

		glTranslatef(6,4,4);
		//glRotatef(angleRot*temps_entier,0,1,1);

		//glTranslatef(-t,0,0); //dans le cas ou on veut une trajectoir rectiligne
		glRotatef(angleRot*temps_entier,1,1,1);
		glScalef(0.75,0.75,0.75);
		dessine_camion(sc);
	glPopMatrix();
}

void rotation_terre(){
	glPushMatrix();
		float t=temps();
		int temps_entier=int(t);
//		float angleRot= 360/NBROT;
        float angleRot= 90;
		glRotatef(-angleRot*temps_entier,0,1,0);
		draw_sphere();
	glPopMatrix();
}

void anim_terre(const Scene& sc){
	glPushMatrix();
		float t=temps();
		int temps_entier=int(t);
		int temps_entier_ok = temps_entier % sc.anim.nbp;

		int suiv=(temps_entier+1)%sc.anim.nbp;
		float poids = t-temps_entier;
		Vec3f pos1,pos2,posf;
		vecSub(pos1,sc.anim.P[suiv],sc.anim.P[temps_entier_ok]);
		vecMul(pos2, poids, pos1);
		vecAdd(posf,pos2,sc.anim.P[temps_entier_ok]);
		glTranslatef(posf.x,posf.y,posf.z);
		glRotatef(180,1,0,0);

		glScalef(0.4,0.4,0.4);
		glEnable(GL_TEXTURE_2D);
		glDisable(GL_BLEND);
		glDisable(GL_ALPHA_TEST);
		glBindTexture(GL_TEXTURE_2D,sc.tex_monde);

		rotation_terre();

		glDisable(GL_TEXTURE_2D);
		glEnable(GL_BLEND);
		glEnable(GL_ALPHA_TEST);
	glPopMatrix();
}

void anim_lune(const Scene& sc){
	glPushMatrix();
		float t=temps();
		int temps_entier=int(t);
		int temps_entier_ok = temps_entier % sc.anim.nbp;

		int suiv=(temps_entier+1)%sc.anim.nbp;
		float poids = t-temps_entier;

		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D,sc.tex_lune);

		Vec3f pos1,pos2,posf;
		vecSub(pos1,sc.anim.P[suiv],sc.anim.P[temps_entier_ok]);
		vecMul(pos2, poids, pos1);
		vecAdd(posf,pos2,sc.anim.P[temps_entier_ok]);
		glTranslatef(posf.x,posf.y,posf.z);
		glRotatef(180,1,0,0);
		//glScalef(0.4,0.4,0.4);
		glScalef(0.3,0.3,0.3);


		rotation_terre();

		glDisable(GL_TEXTURE_2D);
	glPopMatrix();
}

/** Dans le cas où on veut dessiner notre propre arbre avec des formes de Y */
void dessine_arbre_avc_branches(const Scene& sc){
/* int i,k;
    glPushMatrix();
    //glColor3f( 1, 0, 0);
    glScalef(0.2,0.2,0.2);
    for(i=0;i<3;i++)
        //for(j=0;j<3;j++)
            for(k=0;k<3;k++){
                glTranslatef(i-10,0,k+10);
                dArbre(10-i,2);
            }

    glPopMatrix();
*/
/*
    glPushMatrix();
    //glColor3f( 1, 0, 0);
    dBranche(1,3,0);
    glPopMatrix();
*/
}

void sceneDraw(const Scene& sc)
{
/***** Affichage Terrain *****/
    glPushMatrix();
		glBindTexture(GL_TEXTURE_2D,sc.tex_terrain);
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D,sc.tex_terrain);

		glScalef(0.2,0.015,0.2);
		glTranslatef(-192/2,-150,-192/2);

		/*glTranslatef(-5,0,-5);
		glScalef( 0.2,0.2,0.2);
		glScalef( 0.5,0.2,0.5);
		glScalef( 0.5,0.2,0.5);
		glScalef( 1,0.5,1);*/
		dessineTerrain(sc.terrain);
		glScalef((float)1/0.2,(float)1/0.015,(float)1/0.2);
		dessine_foret(sc);
		glDisable(GL_TEXTURE_2D);
    glPopMatrix();

/****** Dessine cubmap *****/
	glPushMatrix();
		glEnable(GL_TEXTURE_2D);
		glScalef(40,40,40);
		glTranslatef(-0.5,-0.1,0.5);
		cubmap(sc);
		glDisable(GL_TEXTURE_2D);
	glPopMatrix();

/****** Soleil Terre Lune *****/
	glPushMatrix();
		glColor3f(1,1,0.5);
		glTranslatef(-1,15,-1);
		glScalef(1,1,1);
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D,sc.tex_soleil);
		draw_sphere();
		glDisable(GL_TEXTURE_2D);
    glPopMatrix();

    glPushMatrix();
		glColor3f(1,1,1);
		glTranslatef(0,12,0);
		anim_terre(sc);
	glPopMatrix();

	glPushMatrix();
		glColor3f(1,1,1);
		glTranslatef(1,13,1);
		glScalef(0.8,0.8,0.8);
		anim_lune(sc);
	glPopMatrix();

/****** Dessine Camion *****/
	glPushMatrix();
		anim_camion(sc);
	glPopMatrix();

}
